package com.ts.proj.service.impl;

import com.ts.base.service.impl.CommonServiceImpl;
import com.ts.proj.entity.InformationEntity;
import com.ts.proj.repository.FinanceRepository;
import com.ts.proj.repository.InformationRepository;
import com.ts.proj.service.FinanceService;
import com.ts.proj.service.InformationService;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


//说明 字符串：，作为替换字符串 LOWERFinance                Finance

@Service
public class InformationServiceImpl extends CommonServiceImpl<InformationEntity>  implements InformationService {

    @Autowired
    private InformationRepository informationRepository;

    @Override
    public List<InformationEntity> findAll(PageData pageData, Integer start, Integer length) {
        Specification<InformationEntity> sp = this.getSpecification(pageData,InformationEntity.class);
        Sort sort = new Sort(Sort.Direction.ASC,"id");
        Pageable pageable = new PageRequest(start, length, sort);
        return informationRepository.findAll(sp,pageable).getContent();
    }

    @Override
    public long count(PageData pageData) {
        Specification<InformationEntity> sp = this.getSpecification(pageData,InformationEntity.class);
        return informationRepository.count(sp);
    }

    @Override
    public boolean deleteByIds(Iterable<InformationEntity> iterable) {
        informationRepository.deleteInBatch(iterable);
        return false;
    }

    @Override
    public List<InformationEntity> saveAll(List<InformationEntity> entities) {
        return informationRepository.saveAll(entities);
    }

    @Override
    public List<InformationEntity> findAllById(Integer[] ids) {
        List<InformationEntity> list = informationRepository.findAllById(Arrays.asList(ids));
        if(list.size()==0){
            InformationEntity entity = new InformationEntity();
            list.add(entity);
        }
        return list;
    }

    @Override
    public boolean deleteAll() {
        informationRepository.deleteAll();
        return false;
    }
}